﻿namespace com.vs.DataAccess
{
    using com.vs.General;
    using System;
    using System.Collections.Generic;
    using System.Data;

    public class SchemaRetrieval
    {
        public static string[] GetDatabaseTables(Session session)
        {
            string[] array = null;
            using (DataHelper helper = new DataHelper(session))
            {
                DataTable table = helper.GetTable(CommandType.Text, "SELECT TABLE_NAME FROM " + SqlRetrieval.GetTableNameForTableList(session), new IDataParameter[0]);
                if (DataManager.IsEmpty(table))
                {
                    return array;
                }
                List<string> list = new List<string>();
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string item = DataManager.GetString(table, i, 0);
                    if (!(((item.ToUpper().Equals("DTPROPERTIES") || item.ToUpper().Equals("UPLOAD_SERIAL_NUMBER_16023")) || item.ToUpper().StartsWith("ASSET")) || item.ToUpper().EndsWith("LPLT_BAK")))
                    {
                        list.Add(item);
                    }
                }
                if (list.Count > 0)
                {
                    array = new string[list.Count];
                    list.CopyTo(array);
                }
            }
            return array;
        }

        public static DataTable GetFieldNamesForTable(Session session, string tableName)
        {
            using (DataHelper helper = new DataHelper(session))
            {
                return helper.GetTable(CommandType.Text, " select column_name from " + SqlRetrieval.GetTableNameForColumnList(session) + " where table_name = @tableName  order by column_name asc ", new IDataParameter[] { helper.BuildParameter("@tableName", tableName) });
            }
        }
    }
}

